'use strict'

const Controller = require('egg').Controller

class LoginController extends Controller {
  async login() {
    const { ctx } = this
    const data = await ctx.service.login.login()
    if (data) {
      ctx.body = {
        status: 200,
        data: null,
        message: '登录成功',
        success: true
      }
    } else {
      ctx.body = {
        status: 201,
        data: null,
        message: '该用户未注册，请先注册',
        success: false
      }
    }
  }
  async register() {
    const { ctx } = this
    const data = await ctx.service.login.register()
    if (data?.uniqno) {
      ctx.body = {
        status: 200,
        data: null,
        message: '注册成功',
        success: true
      }
    } else {
      ctx.body = {
        status: 201,
        data: null,
        message: data,
        success: false
      }
    }
  }
  async logout() {
    const { ctx } = this
    ctx.body = {
      status: 200,
      data: '退出成功',
      success: true
    }
  }
}

module.exports = LoginController
